﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using GC2.ExceptionHandler.Services;
using System.Data.SqlClient;

public partial class Backup_Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        txtRuta.Text = Server.MapPath("~\\000\\") + "GC2.bak";        
        txtBase.Text = "wi530132_GC2";

    }
    protected void btnRestaurar_Click(object sender, EventArgs e)
    {

        Database DataBase = DatabaseFactory.CreateDatabase("GC2Master");
        DbCommand cmd = DataBase.GetStoredProcCommand("DataBaseRestore");

        try
        {
            using (cmd)
            {
                DataBase.AddInParameter(cmd, "@backupFile", DbType.String, txtRuta.Text);
                DataBase.AddInParameter(cmd, "@newDatabaseName", DbType.String, txtBase.Text);

                DataBase.ExecuteNonQuery(cmd);
            }

            Label3.Text = "Backup restaurado";
        }
        catch (SqlException sql_ex)
        {
            ExceptionSQL exNew = new ExceptionSQL();
            Label3.Text = exNew.exSQL(sql_ex.ToString()).ToString();
        }
        catch (Exception ex)
        {
            ExceptionDAL exNew = new ExceptionDAL();
            Label3.Text = exNew.exDAL(ex.ToString()).ToString();
        }
    }
}
